from bisheng.api.sh_api.model.user_chat_relation import UserChat,UserChatDao
from bisheng.database.models.message import ChatMessage, ChatMessageDao, ChatMessageRead, MessageDao


class ShService:
    def __init__(self):
        pass

    @staticmethod
    def create_user_chat(user_id,chat_id):
        user_chat = UserChatDao.select_chat_by_chat_id_and_user_id(chat_id, user_id)
        if user_chat is None:
            user_chat = UserChat(
                user_id=user_id,
                chat_id=chat_id,
                chat_name = "兴宝默认会话"
            )
            user_chat = UserChatDao.create_user_chat(user_chat)
        else:
            user_chat = UserChatDao.update_user_chat(user_chat)
        return user_chat

    @staticmethod
    def get_user_chat(user_id,page_size):
        return UserChatDao.select_chat_by_user_id(user_id,page_size)

    @staticmethod
    def get_user_chat_by_chat_id(chat_id,category_list,page_size):
        return ChatMessageDao.get_messages_by_chat_id(chat_id,category_list,page_size)

    @staticmethod
    def get_message_by_chat_id_desc(chat_id,category_list,page_size):
        return ChatMessageDao.get_messages_by_chat_id_desc(chat_id,category_list,page_size)
